<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="120px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="12">
					<el-form-item label="作业活动类型" prop="zyhdlx" required >
						<el-input v-model="dataForm.zyhdlx" placeholder="请输入作业活动类型" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="作业活动名称" prop="zyhdmc" required >
						<el-input v-model="dataForm.zyhdmc" placeholder="请输入作业活动名称" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="区域/位置" prop="ssqy" required >
						<el-select v-model="dataForm.ssqy" placeholder="请选择区域/位置" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ssqyOptions" :key="index" :label="item.MC" :value="item.ID" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="所属部门" prop="ssbm" required >
						<el-select v-model="dataForm.ssbm" placeholder="请选择所属部门" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ssbmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="风险点编号" prop="fxdbh" >
						<el-input v-model="dataForm.fxdbh" placeholder="系统自动生成" readonly >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12"v-if="false" >
					<el-form-item label="添加人" prop="adduser" >
						<el-input v-model="dataForm.adduser" placeholder="系统自动生成" readonly >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12"v-if="false" >
					<el-form-item label="添加时间" prop="addtime" >
						<el-input v-model="dataForm.addtime" placeholder="系统自动生成" readonly >
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="作业频率" prop="zypl" >
						<el-input v-model="dataForm.zypl" placeholder="请输入作业频率" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="作业图片" prop="image" >
						<JNPF-UploadImg v-model="imageList" accept="" :fileSize="2" sizeUnit="MB" :limit="9" >
						</JNPF-UploadImg>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="备注" prop="bz" >
						<el-input v-model="dataForm.bz" placeholder="请输入备注" show-word-limit :style='{"width":"100%"}' type="textarea" :autosize='{"minRows":4,"maxRows":4}' >
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					zyhdlx:undefined,
					zyhdmc:undefined,
					ssqy:undefined,
					ssbm:undefined,
					fxdbh:undefined,
					adduser:undefined,
					addtime:undefined,
					zypl:undefined,
					image:[],
					bz:undefined,

        },
        rules: {
						zyhdlx:[
						{
							required:true,
							message:'请输入作业活动类型',
							trigger:'blur'
						},
						],
						zyhdmc:[
						{
							required:true,
							message:'请输入作业活动名称',
							trigger:'blur'
						},
						],
						ssqy:[
						{
							required:true,
							message:'请输入区域/位置',
							trigger:'blur'
						},
						],
						ssbm:[
						{
							required:true,
							message:'请输入所属部门',
							trigger:'blur'
						},
						],

        },
				ssqyOptions:[],
				ssbmOptions:[],

					imageList:[],

      }
    },
    created() {
		this.getSsqyOptions();
		this.getSsbmOptions();

    },
    methods: {
		getSsqyOptions()
		{
			previewDataInterface('e7b2c31f5a7147c08629c5409dd7fdf4').then(res => {
				this.ssqyOptions = res.data
			})
		},
		getSsbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.ssbmOptions = res.data
			})
		},

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/ZYHDQD/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;
				this.imageList = this.dataForm.image ? JSON.parse(this.dataForm.image) : [];

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
				this.$set(this.dataForm, 'image', JSON.stringify(this.imageList));

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/ZYHDQD',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/ZYHDQD/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>